﻿using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)

        {
            List<Student> students = new List<Student>();
            string StudentsInfoFilePath = @"D:\Inteducation\Valer_Malin\Student homework\file.txt";

            string exit = "N";
            do
            {
                Console.Clear();
                Console.WriteLine("1-добавление студентов и экспорт в файл");
                Console.WriteLine("2-импорт списка студентов из файла");
                string select = Console.ReadLine();
                string choice = "N";
                if (select == "1")
                {
                    Console.Clear();
                    do
                    {
                        Student student = new Student();
                        student.AddNewStudent();
                        students.Add(student);
                        Console.WriteLine("хотите добавить ещё одного студента? Y/N");
                        choice = Console.ReadLine().ToUpper();
                    }
                    while (choice == "Y");

                    foreach (var stud in students)
                    {
                        File.AppendAllText(StudentsInfoFilePath, "Student ID " + stud.studentID + Environment.NewLine);
                        File.AppendAllText(StudentsInfoFilePath, "Student first Name " + stud.firstName + Environment.NewLine);
                        File.AppendAllText(StudentsInfoFilePath, "Student last Name " + stud.lastName + Environment.NewLine);
                        File.AppendAllText(StudentsInfoFilePath, "\n" + Environment.NewLine);
                    }
                    Console.WriteLine("показать добавленых студентов ? Y/N");
                    if (Console.ReadLine().ToUpper() == "Y")
                    {
                        foreach (var student in students)
                        {
                            Console.WriteLine("Student ID {0}", student.studentID);
                            Console.WriteLine("Student first name {0}", student.firstName);
                            Console.WriteLine("Student last name {0}", student.lastName);
                            Console.WriteLine("\n");
                        }
                        Console.ReadKey();
                        Console.Clear();
                        Console.WriteLine("завершить работу? Y/N");
                        exit = Console.ReadLine().ToUpper();
                    }
                }

                if (select == "2")
                {
                    Console.Clear();
                    string[] text = System.IO.File.ReadAllLines(StudentsInfoFilePath);
                    foreach (var txt in text)
                    {
                        Console.WriteLine(txt);
                    }
                    Console.WriteLine("завершить работу? Y/N");
                    exit = Console.ReadLine().ToUpper();
                }



                if (choice != "Y" && choice!="N")
                    {
                        Console.Clear();
                        Console.WriteLine("неверный ввод");
                        Console.ReadKey();
                    }
                }
                while (exit == "N") ;

            
         }
    }
}
    



